package auth

import (
	"beego/comm/db"
	"beego/comm/utils"
	"encoding/json"
	"fmt"
)

func HandleLogin(requestBody []byte) map[string]interface{} {
	var requestData map[string]interface{}
	json.Unmarshal(requestBody, &requestData)
	user_name := utils.CheckFieldExists(requestData, "userName").(string)
	user_loginID := utils.CheckFieldExists(requestData, "loginID").(string)
	loginID, err := db.RedisGet("login-" + user_name)
	if nil != err {
		panic(fmt.Sprintf("%s", err))
	}
	if loginID == "" || loginID != user_loginID {
		panic("请先登录")
	}
	return requestData
}
